
<@c.html>
<div class="panel panel-_default">
    <div class="panel-heading">
        <h1 class="panel-title" style="font-size: 28px;">
            <a href="./listView">
                <i class="glyphicon glyphicon-chevron-left" style="border: 2px solid #1D2939;border-radius: 50px;font-size: 28px;"></i>
            </a>
            系统用户
        </h1>
    </div>
    <div class="panel-body">
        <div class="row">
            <form class="form-horizontal" id="form-table">
                <input name="id" type="hidden" value="${id!""}"/>
        <div class="form-group">
            <label class="control-label col-sm-3">登录名</label>
            <div class="col-sm-6">
                <input class="form-control" type="text" id="userName" name="userName" required maxlength=32/>
            </div>
            <div class="help-block with-errors col-sm-3"></div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-3">密码</label>
            <div class="col-sm-6">
                <input class="form-control" type="text" id="password" name="password" required maxlength=32/>
            </div>
            <div class="help-block with-errors col-sm-3"></div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-3">姓名</label>
            <div class="col-sm-6">
                <input class="form-control" type="text" id="name" name="name" required maxlength=32/>
            </div>
            <div class="help-block with-errors col-sm-3"></div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-3">状态</label>
            <div class="col-sm-6">
                    <@selectDirective link="user_status" default="1" name="status" type="radio" required="true"/>
            </div>
            <div class="help-block with-errors col-sm-3"></div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-3">角色</label>
            <div class="col-sm-6">
                    <@selectDirective link="sys_role,id,name" default="" name="roleId" type="select" required="true"/>
            </div>
            <div class="help-block with-errors col-sm-3"></div>
        </div>


            </form>
        </div>
        <div class="row text-center">
            <button class="btn btn-primary" id="btn-save">save</button>
        </div>
    </div>
</div>
</@c.html>
<script type="application/javascript">
    $(function(){
        $("#form-table").validator();

        $('#btn-save').click(function(){
            $("#form-table").validator('validate');
            var isValidate = !$('#form-table').validator('hasErrors');
            if(!isValidate) return;

            var params = getFormData($("#form-table"));

            $.ajax({
                type : "post",
                url : '.',
                contentType:"json",
                headers: {"Content-Type":"application/json"},
                data: JSON.stringify(params),
                success:function (result) {
                    console.log(result);
                    window.location.href = './listView';
                },
                error:function(xmlHttpRequest , message,  error){
                    bootbox.alert("error");
                    console.log(message);
                }
            });

            console.log(jsonData);
        });

        <#if id??>
            $.getJSON("./${id}", function(data){
                loadForm($("#form-table"), data);
            });
        <#else>
            initForm();
        </#if>
    });
</script>